package com.yjs.app.trade.web.controller.sys;


import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yjs.app.trade.entity.base.SysConstant;
import com.yjs.app.trade.entity.base.util.Page;
import com.yjs.app.trade.entity.bean.PassportSearch;
import com.yjs.app.trade.service.service.sys.MessagePushService;
import com.yjs.app.trade.service.service.sys.UserService;
import com.yjs.app.trade.web.controller.base.BaseController;
import com.yjs.app.trade.web.controller.base.util.Result;

import net.sf.json.JSONObject;

@Controller
@RequestMapping(value = "/app/sys/message")
public class MessagePushController extends BaseController {

	@Autowired	
	MessagePushService messagePushService;
	
	@Autowired
	UserService userService;

	/**
	 * 获取推送消息列表
	 * @return
	 */
	@RequestMapping(value = "/findMessageByPassportId", method = RequestMethod.GET)
	@ResponseBody
	public Object findMessageByPassportId(String data, HttpServletRequest request,Page<PassportSearch> page, PassportSearch passportSearch) {
		JSONObject dpackData = dpackData(data);
		page.setPageNo(dpackData.getInt("pageNo"));
		if (dpackData.get("pageSize") != null) {
			page.setPageSize(dpackData.getInt("pageSize"));
		}
		passportSearch.setPage(page);
		String passportId = getUserId(request);
		passportSearch.setPassportId(passportId);
		return Result.csuccess(messagePushService.findMessageByPassportId(page,passportSearch));
	}
	
	@RequestMapping(value = "/updataIsCheck", method = RequestMethod.GET)
	@ResponseBody
	public Object updataIsCheck(String data){
		JSONObject dpackData = dpackData(data);
		String id = (String) dpackData.get("id");
		Integer status=2;
		Map<String,Object> map=new HashMap<>();
		map.put("id", id);
		map.put("status", status);
		int isCheck = messagePushService.updataIsCheck(map);
		if(isCheck==1){
			return Result.csuccess("修改成功");
		}
		return Result.cfail(SysConstant.ErrorCode.BUSINESS_ERROR,"修改失败");
	}
}
